home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Examples / PMeter-Alloc_Tests / Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  5.8 KB  |  170 lines

  1. #include <clib/extras_protos.h>
  2. #include <proto/intuition.h>
  3. #include <proto/exec.h>
  4. #include <proto/gadtools.h>
  5. #include <proto/graphics.h>
  6. #include <proto/diskfont.h>
  7. #include <proto/dos.h>
  8. #include <stdio.h>
  9. #include <exec/memory.h>
  10. #include <stdlib.h>
  11.  
  12. extern struct Custom custom;
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase *GfxBase;
  15. struct Library *GadToolsBase, 
  16.                *DiskfontBase;
  17.  
  18. struct Libs Libs[]=
  19. {
  20.   (APTR)&DiskfontBase , (STRPTR)"diskfont.library" , 36, 0,
  21.   (APTR)&GfxBase      , (STRPTR)"graphics.library" , 36, 0,
  22.   (APTR)&GadToolsBase , (STRPTR)"gadtools.library" , 36, 0,
  23.   (APTR)&IntuitionBase, (STRPTR)"intuition.library", 36, 0,
  24.   0,0,0,0
  25. };
  26.  
  27. void main(int argc, char **argv)
  28. {
  29.   LONG l;
  30.   APTR a=0,b=0,c=0;
  31.   APTR pool;
  32.   BOOL success;
  33.   ProgressMeter pm[3];
  34.   LONG t,m=3;
  35.   struct Screen *s;
  36.   ULONG canceled=0,can;
  37.           
  38.   if(OpenLibs(argc,(STRPTR)"TestProg",0,0,0,Libs))
  39.   {
  40.     s=LockPubScreen(0);
  41.     
  42.     printf("Testing Progress Meter...\nCancel the requester to continue\n");
  43.     
  44.     pm[0]=AllocProgressMeter(
  45.                           PM_WinTitle  ,        (ULONG)"Demo Meter 1",
  46.                           PM_MeterLabel,        (ULONG)"Formating disk...",
  47.                           PM_LowText   ,        (ULONG)"0%",
  48.                           PM_HighText  ,        (ULONG)"100%",
  49.                           PM_Screen,            s,
  50.                           PM_TextAttr,          s->Font,
  51.                           PM_Ticks,             5,
  52.                           PM_HighValue,         200,
  53.                           PM_MeterValue,        100,
  54.                           PM_CancelButton,      TRUE,
  55.                           PM_CancelText,        (ULONG)"Stop",
  56.                           TAG_DONE);
  57.                           
  58.     pm[1]=AllocProgressMeter(PM_WinTitle  ,     "Demo Meter 2",
  59.                           PM_MeterLabel,        "Hex-o-meter",
  60.                           PM_LowText   ,        "0",
  61.                           PM_HighText  ,        "200",
  62.                           PM_CancelButton,      TRUE,
  63.                           PM_CancelText,        "Cancel",
  64.                           PM_Screen,            s,
  65.                           PM_MinWidth,          320,
  66.                           PM_TextAttr,          s->Font,
  67.                           PM_Ticks,             10,
  68.                           PM_HighValue,         200,
  69.                           PM_MeterValue,        10,
  70.                           PM_MeterPen   ,       1,
  71.                           PM_MeterBgPen ,       3, 
  72.                           PM_MeterType,         PM_TYPE_NUMBER,
  73.                           PM_MeterFormat,       "%X",
  74.                           TAG_DONE);
  75.    pm[2]=AllocProgressMeter(PM_WinTitle  ,      "Demo Meter 3",
  76.                           PM_MeterLabel,        "Volume",
  77.                           PM_LowText   ,        "0%",
  78.                           PM_HighText  ,        "100%",
  79.                           PM_Screen,            s,
  80.                           PM_TextAttr,          s->Font,
  81.                           PM_Ticks,             1,
  82.                           PM_MinWidth,          128,
  83.                           PM_LowValue,          0,
  84.                           PM_HighValue,         128*4,
  85.                           PM_MeterValue,        10,
  86.                           PM_MeterType,         PM_TYPE_STRING,
  87.                           PM_MeterFormat,       "",
  88.                           TAG_DONE);
  89.     while(!canceled)
  90.     for(l=0;l<201 && !canceled;l++)
  91.     {
  92.       for(t=0;t<m;t++)
  93.       {
  94.         WaitTOF();
  95.         WaitTOF();
  96.         UpdateProgressMeter(pm[t],
  97.                          PM_MeterValue  ,l,
  98.                          PM_QueryCancel ,&can,
  99.                          TAG_DONE);
  100.         canceled+=can;
  101.       }
  102.     }
  103.     
  104.     for(t=0;t<m;t++)
  105.       FreeProgressMeter(pm[t]);
  106.     
  107.     UnlockPubScreen(0,s);
  108.     
  109.     
  110.     printf("MultiAllocX() tests\n");
  111.     /* Multiple AllocVec */
  112.     success=MultiAllocVec(0,&a, 100,MEMF_CLEAR,
  113.                     &b, 120,MEMF_PUBLIC,
  114.                     &c,   8,MEMF_FAST,
  115.                     0);
  116.     printf("Vec  success=%d  a=%8x  b=%8x  c=%8x\n",success,a,b,c);
  117.     MultiFreeVec(3,a,
  118.                    b,
  119.                    c);
  120.  
  121.  
  122.     /* Multiple AllocMem */
  123.     MultiAllocMem(0,&a, 100,MEMF_CLEAR,
  124.                     &b, 120,MEMF_PUBLIC,
  125.                     &c,   8,MEMF_FAST,
  126.                     0);
  127.     printf("Mem  success=%d  a=%8x  b=%8x  c=%8x\n",success,a,b,c);
  128.     MultiFreeMem(3,a,100,
  129.                    b,120,
  130.                    c,8);
  131.  
  132.     /* Multiple AllocPooled */
  133.     if(pool=CreatePool(MEMF_CLEAR,1000,1000))
  134.     {
  135.       MultiAllocPooled(pool,0,&a, 100,
  136.                               &b, 120,
  137.                               &c,   8,
  138.                               0);
  139.       printf("Pool success=%d  a=%8x  b=%8x  c=%8x\n",success,a,b,c);
  140.       MultiFreePooled(pool,3,a, 100,
  141.                              b, 120,
  142.                              c, 8);
  143.       DeletePool(pool);
  144.     }     
  145.  
  146.     /* the following demonstrate the MA_FAILSIZE0 flag */
  147.     /* Multiple AllocVec without MA_FAILSIZE0 flag*/
  148.     success=MultiAllocVec(0,&a, 0    ,MEMF_CLEAR,
  149.                             &b, 120  ,MEMF_PUBLIC,
  150.                             &c, 8    ,MEMF_FAST,
  151.                             0);
  152.     printf("Vec  success=%d  a=%8x  b=%8x  c=%8x  without MA_FAILSIZE0\n",success,a,b,c);
  153.     MultiFreeVec(3,a,
  154.                    b,
  155.                    c);
  156.     
  157.     /* Multiple AllocVec with MA_FAILSIZE0 flag*/
  158.     success=MultiAllocVec(MA_FAILSIZE0, &a, 0   ,MEMF_CLEAR,
  159.                                         &b, 120 ,MEMF_PUBLIC,
  160.                                         &c, 8   ,MEMF_FAST,
  161.                                         0);
  162.     printf("Vec  success=%d  a=%8x  b=%8x  c=%8x  with MA_FAILSIZE0\n",success,a,b,c);
  163.     MultiFreeVec(3,a,
  164.                    b,
  165.                    c);
  166.  
  167.     CloseLibs(Libs);
  168.   }
  169. }
  170.